#include<vector>
using namespace std;
class Solution {
public:
    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        vector<int>dp(obstacleGrid[0].size());
        dp[0] = obstacleGrid[0][0] == 0;
        for (int i = 0; i < obstacleGrid.size(); ++i) {
            for (int j = 0; j < obstacleGrid[i].size(); ++j) {
                if (obstacleGrid[i][j] == 1) dp[j] = 0;
                else {
                    if (j > 0 && obstacleGrid[i][j-1] == 0)
                        dp[j] += dp[j-1];
                }
            }
        }
        return dp.back();
    }
};

//int main() {
//    Solution sol;
//    vector<vector<int>> obstacleGrid = { {0,0,0},{0,1,0},{0,0,0} };
//    sol.uniquePathsWithObstacles(obstacleGrid);
//}